import React from 'react';
import PropTypes from "prop-types";

export default class Provider extends React.Component
{
    /**
     * 属性类型
     */
    static propTypes =
    {
        store : PropTypes.object.isRequired,
        children : PropTypes.element.isRequired
    };

    /**
     * 申明上下文属性
     */
    static childContextTypes =
    {
        store: PropTypes.object
    };

    constructor (props, context, updater)
    {
        super(props, context, updater);
        this.store = props.store;
    }

    /**
     * 返回上下文属性
     */
    getChildContext ()
    {
        return {store : this.store}
    }

    render ()
    {
        return React.Children.only(this.props.children);
    }
}